package com.zat.mes.andrmes.dofun.main

import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.text.TextUtils
import android.util.Log
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.Gson
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.LoginResultBean
import com.zat.mes.andrmes.dofun.system.LoginActivity
import com.zat.mes.andrmes.global.CompanionType
import com.zat.mes.andrmes.utils.PreferencesUtil

/**
 * 欢迎页activity
 */
class WelcomeActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_welcome)

    }

    override fun onStart() {
        super.onStart()
        Handler().postDelayed(Runnable {
            val loginResultBean = Gson().fromJson(
                PreferencesUtil.getString(CompanionType.LOGIN_RESULT),
                LoginResultBean::class.java
            )
            if (TextUtils.isEmpty(PreferencesUtil.getString(CompanionType.TOKEN))) {
                try {
                    startActivity(Intent(this, LoginActivity::class.java))
                } catch (e: ActivityNotFoundException) {
                    Log.e("activity", e.toString())
                }
            } else {
                try {
                    startActivity(Intent(this, MainActivity::class.java))
                } catch (e: ActivityNotFoundException) {
                    Log.e("activity", e.toString())
                }

            }
            finish()
        }, 2000);

    }
}
